class RulesController < ApplicationController
  
  def index
    @new_rule = Rule.new
    @search = Search.new
    @rules = Rule.all
  end
  
  def create
    # create the search
    search = Search.find_or_create_by_query(params[:search][:query])
    # create the rule
    Rule.find_or_create_by_search_id(search.id)
    redirect_to(:action => :index)
  end
  
  def destroy
    Rule.destroy(params[:id])
    redirect_to(:action => :index)
  end
end